package main.剑指OfferⅠ;

import java.util.Stack;

public class Day1 {
    public static void main(String[] args) {
        System.out.println("剑指Offer09.用两个栈实现队列");
        System.out.println("剑指Offer30.包含min函数的栈");
    }
}

class Offer09{
    Stack<Integer> addStack,popStack;
    public Offer09() {
        addStack=new Stack<>();
        popStack=new Stack<>();
    }

    public void appendTail(int value) {
        addStack.add(value);
    }

    public int deleteHead() {
        int temp=-1;
        while (!addStack.isEmpty()){
            popStack.add(addStack.pop());
        }
        if (!popStack.isEmpty()) temp= popStack.pop();
        while (!popStack.isEmpty()){
            addStack.add(popStack.pop());
        }
        return temp;
    }
}

class Offer30{
    Stack<Integer> mainStack,assistStack;
    /** initialize your data structure here. */
    public Offer30() {
        mainStack=new Stack<>();
        assistStack=new Stack<>();//压入最小值
        assistStack.add(Integer.MAX_VALUE);
    }

    public void push(int x) {
        mainStack.add(x);
        assistStack.add(Math.min(x,assistStack.peek()));
    }

    public void pop() {
        mainStack.pop();
        assistStack.pop();
    }

    public int top() {
        return mainStack.peek();
    }

    public int min() {
        return assistStack.peek();
    }
}